//index.js
const util = require('../../utils/util.js');

//获取应用实例
var app = getApp()
Page({
  data: {
    cities: [],
    banners: [],
    notices: [],
    goodProducts: [],
    hotProducts: [],
    recentlyProducts: [],
  },

  onLoad: function () {
    wx.showLoading({
      title: '',
    });
    this.getCities();
    this.getBanners();
    this.getNotices();
    this.getPorducts();
  },
  getCities() {
    util.request(util.apiUrl + '/cities', 'GET').then((res) => {
      this.setData({
        cities: res.list
      })
    });
  },
  getBanners() {
    util.request(util.apiUrl + '/banners', 'GET').then((res) => {
      this.setData({
        banners: res.list
      })
    });
  },
  getNotices() {
    util.request(util.apiUrl + '/notices', 'GET').then((res) => {
      this.setData({
        notices: res.list
      });
    });
  },
  getPorducts() {
    util.request(util.apiUrl + '/products', 'GET').then((res) => {
      this.setData({
        goodProducts: res.good_products,
        hotProducts: res.hot_products,
        recentlyProducts: res.recently_products
      });
      wx.hideLoading();
    }).catch(err => {
      wx.hideLoading();
    });
  }
})
